package org.lyl.vhr.service;

import org.lyl.vhr.mapper.HrMapper;
import org.lyl.vhr.model.Hr;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author lylbell
 * @date 2020-07-31 08:58
 */
@Service
public class HrService implements UserDetailsService {

    @Autowired
    HrMapper hrMapper;


    //通过用户名判断用户是否存在
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Hr hr = hrMapper.loadUserByUsername(username);
        if (hr == null) {
            throw new UsernameNotFoundException("用户不存在！");
        }
        return hr;
    }
}
